/*  little.m
 *
 *  A minimal program designed to show how the basic objects provided
 *  by the Application Kit fit together.  This program doesn't define
 *  any classes of its own and doesn't use Interface Builder to set up
 *  its user interface.
 *
 *  It has one standard window that you can type in, a main menu with
 *  just the three basic commands, and an empty information panel that
 *  contains no information.  Nevertheless, all three windows behave
 *  exactly as they would in a more elaborate application.
 */


#import <appkit/appkit.h>

void setUp(void)
{
	id	 myWindow, myPanel, myMenu, windowText;
	NXRect	 aRect;


	/*** Step 1:  Set up a Window ***/
	NXSetRect(&aRect, 100.0, 350.0, 300.0, 300.0);
	myWindow = [[Window alloc] initContent:&aRect
					style:NX_TITLEDSTYLE
					backing:NX_BUFFERED
					buttonMask:NX_MINIATURIZEBUTTONMASK
					defer:NO];
	[myWindow setTitle:"A Little Demonstration"];

	NXSetRect(&aRect, 0.0, 0.0, 300.0, 300.0);
	windowText = [[Text alloc] initFrame:&aRect
					text:""
					alignment:NX_LEFTALIGNED];
	[windowText setOpaque:YES];
	[[myWindow contentView] addSubview:windowText];


	/*** Step 2:  Set up a Panel ***/
	NXSetRect(&aRect, 100.0, 700.0, 300.0, 40.0);
	myPanel = [[Panel alloc] initContent:&aRect
					style:NX_TITLEDSTYLE
					backing:NX_BUFFERED
					buttonMask:NX_CLOSEBUTTONMASK
					defer:YES];
	[myPanel setTitle:"About Little"];
	[myPanel removeFromEventMask:(NX_KEYDOWNMASK | NX_KEYUPMASK)];


	/*** Step 3:  Set up a Menu ***/
	myMenu = [[Menu alloc] initTitle:"Little"];
	[[myMenu addItem:"Info..."
			action:@selector(orderFront:)
			keyEquivalent:'\0']
			setTarget:myPanel];
	[myMenu addItem:"Hide"
			action:@selector(hide:)
			keyEquivalent:'h'];
	[myMenu addItem:"Quit"
			action:@selector(terminate:)
			keyEquivalent:'q'];
	[myMenu sizeToFit];
	[NXApp setMainMenu:myMenu];


	/*** Step 4:  Display all windows that aren't deferred ***/
	[myWindow display];


	/*** Step 5:  Move the principal window on-screen ***/
	[myWindow orderFront:nil];


	/*** Step 6:  Make it the key window ***/
	[myWindow makeKeyWindow];


	/*** Step 7:  Show a selection in the key window ***/
	[windowText selectAll:nil];
}


main()
{
	[Application new];
	setUp();
	[NXApp run];
	[NXApp free];
}
